package org.dizena.modules.master.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.dizena.common.pojo.PageReq;
import org.dizena.common.pojo.PageResp;
import org.dizena.common.pojo.master.ResVO;
import org.dizena.common.pojo.master.TreeVO;
import org.dizena.modules.master.bean.Res;
import org.dizena.modules.master.service.ResService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管理-资源
 */
@RestController
@RequiresPermissions("master:res:*")
@RequestMapping("/api/v1/res")
public class ApiResController
{

    @Resource
    private ResService service;

    /**
     * 资源-枚举
     */
    @PostMapping("list")
    public PageResp<ResVO> list(PageReq req)
    {
        return service.list(req);
    }

    /**
     * 资源-新增
     */
    @PostMapping("add")
    public String add(@Validated Res m)
    {
        return service.add(m);
    }

    /**
     * 资源-删除
     */
    @PostMapping("del")
    public String del(String id)
    {
        return service.del(id);
    }

    /**
     * 资源-更新
     */
    @PostMapping("edit")
    public String edit(Res m)
    {
        return service.edit(m);
    }

    /**
     * 资源-明细
     */
    @PostMapping("get")
    public Res get(String id)
    {
        return service.get(id);
    }

    /**
     * 资源-父级菜单
     */
    @PostMapping("level")
    public List<Res> level(@RequestParam(value = "level", defaultValue = "1") Integer level)
    {
        return service.level(level);
    }

    /**
     * 资源展示
     */
    @GetMapping("view")
    public List<TreeVO> view()
    {
        return service.getTree();
    }



}
